export class IndexService {
  constructor() { }
  verifyStep(activeIndex, formData) {
    let result = {};
    let rules = [];
    switch (activeIndex) {
      case 1:
        rules = [
          { rule: formData.exchange_product.data.length > 0, message: '请添加换货产品' },
          { rule: formData.carryway_id !== '', message: '请选择承运方式' }
        ];
        result = checkRule(rules);
        break;
      default:
        result.pass = true;
        break;
    }
    return result;
  }
}

/**
 * 检查规则，遇到rule=false的情况，立即扔出结果
 * @param {rule:bool, message:string} verifyRules
 */
function checkRule(verifyRules) {
  let result = { pass: true, message: '' };
  for (let i = 0; i < verifyRules.length; i++) {
    const element = verifyRules[i];
    if (element.rule === true) {
      result.pass = true;
    } else {
      result.message = element.message;
      result.pass = false;
      return result;
    }
  }
  return result;
}
